package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/7/28 16:07
 * Version:1.0-SNAPSHOT
 * Description:
 */
@Controller
@RequestMapping("/url")
public class URLController {

    // *:匹配一层路径
    @RequestMapping("/f1/*")
    public void f1(){
        System.out.println("URLController.f1");
    }

    // **:匹配0或多层路径
    @RequestMapping("/f2/**")
    public void f2(){
        System.out.println("URLController.f2");
    }

    // ?:匹配一个字符
    @RequestMapping("/f3/?")
    public void f3(){
        System.out.println("URLController.f3");
    }

    @RequestMapping("/f4/{name}")
    public void f4(@PathVariable("name") String name){
        System.out.println("name:"+name);
    }

    @RequestMapping("/f5/{username}/{password}")
    public void f5(@PathVariable("password") String username,@PathVariable("username") String password){
        System.out.println("username:"+username+",password:"+password);
    }

    @RequestMapping("/f6/{username}/{password}")
    public void f6(@PathVariable String username,@PathVariable String password){
        System.out.println("username:"+username+",password:"+password);
    }

    @RequestMapping("/f7/{id}")
    public void f7(@PathVariable Integer id){
        System.out.println("id:"+id);
    }

    // 可以对用户输入的值进行限制
    // 只有符合指定格式的值才能访问
    @RequestMapping("/f8/{id:\\d+}")
    public void f8(@PathVariable Integer id){
        System.out.println("id:"+id);
    }

    // 当value属性的值是一个数组时
    // 数组中的每一个元素均为该Handler方法的访问命令
    @RequestMapping(value = {"/f9","/test9"})
    public void f9(){
        System.out.println("URLController.f9");
    }

    @ResponseBody
    @RequestMapping(value = "/f10",method = RequestMethod.GET)
    public String f10(){
        return "<h1>Hello f10</h1>";
    }

    @ResponseBody
    //  @RequestMapping(value = "/f11",method = RequestMethod.GET)
    @GetMapping("/f11")
    public String f11(){
        return "<h1>Hello f11</h1>";
    }

    // 限制请求中的数据必须包含key为name的数据
    @RequestMapping(value = "/f12",params = "name")
    public void f12(String name){
        System.out.println("name:"+name);
    }

    // 限制请求中的数据必须包含key为name的数据
    // 且name的值必须为admin
    @RequestMapping(value = "/f13",params = "name=admin")
    public void f13(String name){
        System.out.println("name:"+name);
    }

    // 限制请求中的参数如果有name的数据,其值不能为admin
    // 包含没有name的请求
    @RequestMapping(value = "/f14",params = "name!=admin")
    public void f14(String name){
        System.out.println("name:"+name);
    }
}
